#!/bin/bash

# Method of use
# UserParameter=redis_status[*],/bin/bash /usr/local/zabbix_agent/script/redis_status.sh "$1"
# zabbix_agent.conf

COMMAND=$1
PORT="6379"  #根据实际情况调整端口
SERVER="127.0.0.1"  #根据具体情况调整IP地址
PASSWD=""     #如果没有设置Redis密码,为空即可
redis_status(){
   (echo -en "AUTH $PASSWD\r\nINFO\r\n";sleep 1;) | /usr/bin/nc "$SERVER" "$PORT" > /tmp/redis_"$PORT".tmp
      REDIS_STAT_VALUE=$(grep "$COMMAND:" /tmp/redis_"$PORT".tmp | cut -d ':' -f2)
       echo "$REDIS_STAT_VALUE"
}

used_cpu_user_children() {
  redis_status "$PORT" "$COMMAND"
}

used_cpu_sys() {
  redis_status "$PORT" "$COMMAND"
}

total_commands_processed() {
  redis_status "$PORT" "$COMMAND"
}

role() {
	redis_status "$PORT" "$COMMAND"
}

lru_clock() {
	redis_status "$PORT" "$COMMAND"
}

latest_fork_usec() {
	redis_status "$PORT" "$COMMAND"
}

keyspace_misses() {
	redis_status "$PORT" "$COMMAND"
}

keyspace_hits() {
  redis_status "$PORT" "$COMMAND"
}

keys() {
 	redis_status "$PORT" "$COMMAND"
}

expires() {
	redis_status "$PORT" "$COMMAND"
}

expired_keys() {
	redis_status "$PORT" "$COMMAND"
}

evicted_keys() {
	redis_status "$PORT" "$COMMAND"
}

connected_clients() {
	redis_status "$PORT" "$COMMAND"
}

changes_since_last_save() {
	redis_status "$PORT" "$COMMAND"
}

blocked_clients() {
	redis_status "$PORT" "$COMMAND"
}

bgsave_in_progress() {
	redis_status "$PORT" "$COMMAND"
}

bgrewriteaof_in_progress() {
	redis_status "$PORT" "$COMMAND"
}

used_memory_peak() {
	redis_status "$PORT" "$COMMAND"
}

used_memory() {
	redis_status "$PORT" "$COMMAND"
}

used_cpu_user() {
	redis_status "$PORT" "$COMMAND"
}

used_cpu_sys_children() {
	redis_status "$PORT" "$COMMAND"
}

total_connections_received() {
	redis_status "$PORT" "$COMMAND"
}

$1